From 3d94c63b909efdda6c5eba750985f65080752f9d Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Mon, 24 Aug 2015 15:05:09 +1000 Subject: [PATCH] API: Rename disablepp and introduce disabletidy * Rename disablepp to disablelimitreport, since it does not disable the preprocessor (which is what PP stands for in "NewPP"). * Introduce new option "disabletidy" for T89331 * Suppress the use of the parser cache when options are specified that affect the output but are not in ParserOptions::optionsHash(). This was already broken, but the damage was fairly limited since the options rarely caused user-visible changes. It would break very badly if I use the disabletidy option for what I am intending. Change-Id: I4b0e55fe34e237a68450f583bf59bab7dd703a29 --- includes/api/ApiParse.php | 60 +++++++++++++++++++++++++++++++------- includes/api/i18n/en.json | 8 +++-- includes/api/i18n/qqq.json | 2 ++ 3 files changed, 56 insertions(+), 14 deletions(-) diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 1b8f6d94aa..d67655b97f 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -169,9 +169,23 @@ class ApiParse extends ApiBase { $popts = $this->makeParserOptions( $pageObj, $params ); - // Potentially cached - $p_result = $this->getParsedContent( $pageObj, $popts, $pageid, - isset( $prop['wikitext'] ) ); + // Don't pollute the parser cache when setting options that aren't + // in ParserOptions::optionsHash() + $suppressCache = + $params['disablepp'] || + $params['disablelimitreport'] || + $params['preview'] || + $params['sectionpreview'] || + $params['disabletidy']; + + if ( $suppressCache ) { + $this->content = $this->getContent( $pageObj, $pageid ); + $p_result = $this->content->getParserOutput( $titleObj, null, $popts ); + } else { + // Potentially cached + $p_result = $this->getParsedContent( $pageObj, $popts, $pageid, + isset( $prop['wikitext'] ) ); + } } } else { // Not $oldid, $pageid, $page. Hence based on $text $titleObj = Title::newFromText( $title ); @@ -464,10 +478,13 @@ class ApiParse extends ApiBase { protected function makeParserOptions( WikiPage $pageObj, array $params ) { $popts = $pageObj->makeParserOptions( $this->getContext() ); - $popts->enableLimitReport( !$params['disablepp'] ); + $popts->enableLimitReport( !$params['disablepp'] && !$params['disablelimitreport'] ); $popts->setIsPreview( $params['preview'] || $params['sectionpreview'] ); $popts->setIsSectionPreview( $params['sectionpreview'] ); $popts->setEditSection( !$params['disableeditsection'] ); + if ( $params['disabletidy'] ) { + $popts->setTidy( false ); + } return $popts; } @@ -480,14 +497,9 @@ class ApiParse extends ApiBase { * @return ParserOutput */ private function getParsedContent( WikiPage $page, $popts, $pageId = null, $getWikitext = false ) { - $this->content = $page->getContent( Revision::RAW ); //XXX: really raw? + $this->content = $this->getContent( $page, $pageId ); if ( $this->section !== false && $this->content !== null ) { - $this->content = $this->getSectionContent( - $this->content, - !is_null( $pageId ) ? 'page id ' . $pageId : $page->getTitle()->getPrefixedText() - ); - // Not cached (save or load) return $this->content->getParserOutput( $page->getTitle(), null, $popts ); } @@ -506,6 +518,27 @@ class ApiParse extends ApiBase { } /** + * Get the content for the given page and the requested section. + * + * @param WikiPage $page + * @param int $pageId + * @return Content + */ + private function getContent( WikiPage $page, $pageId = null ) { + $content = $page->getContent( Revision::RAW ); //XXX: really raw? + + if ( $this->section !== false && $content !== null ) { + $content = $this->getSectionContent( + $content, + !is_null( $pageId ) ? 'page id ' . $pageId : $page->getTitle()->getPrefixedText() + ); + } + return $content; + } + + /** + * Extract the requested section from the given Content + * * @param Content $content * @param string $what Identifies the content in error messages, e.g. page title. * @return Content|bool @@ -762,8 +795,13 @@ class ApiParse extends ApiBase { 'sectiontitle' => array( ApiBase::PARAM_TYPE => 'string', ), - 'disablepp' => false, + 'disablepp' => array( + ApiBase::PARAM_DFLT => false, + ApiBase::PARAM_DEPRECATED => true, + ), + 'disablelimitreport' => false, 'disableeditsection' => false, + 'disabletidy' => false, 'generatexml' => array( ApiBase::PARAM_DFLT => false, ApiBase::PARAM_HELP_MSG => array( diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index d3189c6194..396f5dac71 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -302,16 +302,18 @@ "apihelp-parse-paramvalue-prop-iwlinks": "Gives interwiki links in the parsed wikitext.", "apihelp-parse-paramvalue-prop-wikitext": "Gives the original wikitext that was parsed.", "apihelp-parse-paramvalue-prop-properties": "Gives various properties defined in the parsed wikitext.", - "apihelp-parse-paramvalue-prop-limitreportdata": "Gives the limit report in a structured way. Gives no data, when $1disablepp is set.", - "apihelp-parse-paramvalue-prop-limitreporthtml": "Gives the HTML version of the limit report. Gives no data, when $1disablepp is set.", + "apihelp-parse-paramvalue-prop-limitreportdata": "Gives the limit report in a structured way. Gives no data, when $1disablelimitreport is set.", + "apihelp-parse-paramvalue-prop-limitreporthtml": "Gives the HTML version of the limit report. Gives no data, when $1disablelimitreport is set.", "apihelp-parse-paramvalue-prop-parsetree": "The XML parse tree of revision content (requires content model $1)", "apihelp-parse-param-pst": "Do a pre-save transform on the input before parsing it. Only valid when used with text.", "apihelp-parse-param-onlypst": "Do a pre-save transform (PST) on the input, but don't parse it. Returns the same wikitext, after a PST has been applied. Only valid when used with $1text.", "apihelp-parse-param-effectivelanglinks": "Includes language links supplied by extensions (for use with $1prop=langlinks).", "apihelp-parse-param-section": "Only retrieve the content of this section number or when new generate a new section.\n\nnew section is only honored when specifying text.", "apihelp-parse-param-sectiontitle": "New section title when section is new.\n\nUnlike page editing, this does not fall back to summary when omitted or empty.", - "apihelp-parse-param-disablepp": "Omit the preprocessor report (\"NewPP limit report\") from the parser output.", + "apihelp-parse-param-disablelimitreport": "Omit the limit report (\"NewPP limit report\") from the parser output.", + "apihelp-parse-param-disablepp": "Use $1disablelimitreport instead.", "apihelp-parse-param-disableeditsection": "Omit edit section links from the parser output.", + "apihelp-parse-param-disabletidy": "Do not run HTML cleanup (e.g. tidy) on the parser output.", "apihelp-parse-param-generatexml": "Generate XML parse tree (requires content model $1; replaced by $2prop=parsetree).", "apihelp-parse-param-preview": "Parse in preview mode.", "apihelp-parse-param-sectionpreview": "Parse in section preview mode (enables preview mode too).", diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json index 5ac1e0dd77..ef803f5c59 100644 --- a/includes/api/i18n/qqq.json +++ b/includes/api/i18n/qqq.json @@ -292,8 +292,10 @@ "apihelp-parse-param-effectivelanglinks": "{{doc-apihelp-param|parse|effectivelanglinks}}", "apihelp-parse-param-section": "{{doc-apihelp-param|parse|section}}", "apihelp-parse-param-sectiontitle": "{{doc-apihelp-param|parse|sectiontitle}}", + "apihelp-parse-param-disablelimitreport": "{{doc-apihelp-param|parse|disablelimitreport}}", "apihelp-parse-param-disablepp": "{{doc-apihelp-param|parse|disablepp}}", "apihelp-parse-param-disableeditsection": "{{doc-apihelp-param|parse|disableeditsection}}", + "apihelp-parse-param-disabletidy": "{{doc-apihelp-param|parse|disabletidy}}", "apihelp-parse-param-generatexml": "{{doc-apihelp-param|parse|generatexml|params=* $1 - Value of the constant CONTENT_MODEL_WIKITEXT|paramstart=2}}", "apihelp-parse-param-preview": "{{doc-apihelp-param|parse|preview}}", "apihelp-parse-param-sectionpreview": "{{doc-apihelp-param|parse|sectionpreview}}", -- 2.20.1